package com.egu.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.egu.model.CustomerType;
import com.egu.service.CustomerTypeService;
import com.egu.vo.PageParam;
import com.egu.vo.RequestPageVo;
import com.egu.vo.RequestResultVo;

@Controller
@RequestMapping("customerType")
public class CustomerTypeController {

	@Autowired
	private CustomerTypeService customerTypeService;

	@RequestMapping("listUI")
	public String listUI() {
		return "customerType/listUI";
	}

	// rder = "asc" offset = 0 limit = 10;
	@RequestMapping("/getList")
	@ResponseBody
	public RequestPageVo<CustomerType> getList(@ModelAttribute(value = "param") PageParam param, CustomerType customerType) {
		RequestPageVo<CustomerType> vo = customerTypeService.getList(param, customerType);
		return vo;
	}
	@RequestMapping("/getAllList")
	@ResponseBody
	public RequestResultVo<List<CustomerType>> getList() {
		RequestResultVo<List<CustomerType>> vo = customerTypeService.getAllList();
		return vo;
	}
	
	
	

	@RequestMapping("/saveOrUpdate")
	@ResponseBody
	public RequestResultVo<CustomerType> saveOrUpdate(CustomerType customerType) {
		RequestResultVo<CustomerType> result = new RequestResultVo<CustomerType>();
		if (customerType != null) {
			return customerTypeService.saveOrUpdate(customerType);
		} else {
			result.setSuccess(false);
		}
		return result;
	}
	
	@RequestMapping("/deleteDataById")
	public @ResponseBody RequestResultVo<CustomerType> deleteDataById(
			@RequestParam(value = "id", required = false) Integer id) {
		RequestResultVo<CustomerType> result = new RequestResultVo<CustomerType>();
		if (id == null) {
			result.setSuccess(false);
			result.setErrorMessage("传入id为空");
			return result;
		}
		result = customerTypeService.deleteDataById(id);
		return result;
	}
}
